
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -g
LDFLAGS = -lcurl -lm

# 检查系统类型，确定cJSON库的位置
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
    CJSON_INC = -I/usr/include/cjson
    CJSON_LIB = -lcjson
endif
ifeq ($(UNAME_S),Darwin)
    CJSON_INC = -I/opt/homebrew/include/cjson
    CJSON_LIB = -L/opt/homebrew/lib -lcjson
endif

TARGET = weather
SOURCES = weather.c

all: $(TARGET)

$(TARGET): $(SOURCES)
	$(CC) $(CFLAGS) $(SOURCES) -o $(TARGET) $(LDFLAGS) $(CJSON_LIB) $(CJSON_INC)

clean:
	rm -f $(TARGET)

install-deps:
ifeq ($(UNAME_S),Linux)
	sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev libcjson-dev
endif
ifeq ($(UNAME_S),Darwin)
	brew install curl cjson
endif

.PHONY: all clean install-deps
